package com.chris.homecare.screens
{
	import com.chris.homecare.TextureAtlasManager;
	import com.chris.homecare.components.BreadcrumbComponenet;
	import com.chris.homecare.components.BulletHeadingComp;
	import com.chris.homecare.components.HeaderComponent;
	import com.chris.homecare.data.FetchRemoteData;
	import com.chris.homecare.data.ReviewData;
	import com.chris.homecare.utils.CommonUtils;
	import com.chris.homecare.utils.ScreenNames;
	
	import feathers.controls.ImageLoader;
	import feathers.controls.Label;
	import feathers.controls.LayoutGroup;
	import feathers.controls.Screen;
	import feathers.controls.ScrollContainer;
	import feathers.layout.AnchorLayout;
	import feathers.layout.AnchorLayoutData;
	import feathers.layout.VerticalLayout;
	
	import starling.display.Quad;
	import starling.events.Event;
	
	public class DetailReviewScreen extends Screen
	{
		private var header:HeaderComponent;
		private var breadcrumbComp:BreadcrumbComponenet;
		private var ratingImg:ImageLoader;
		private var nameLabel:Label;

		private var bulletHeadingComp:BulletHeadingComp;
		private var titleLabel:Label;
		private var reviewText:Label;

		private var ratingLayoutGroup:LayoutGroup;
		private var reviewData:ReviewData;

		private var contentLayoutGroup:ScrollContainer;
		
		public function DetailReviewScreen()
		{
			super();
		}
		
		override protected function initialize():void
		{
			CommonUtils.previousScreen = ScreenNames.REVIEW_LIST_SCREEN;
			
			reviewData = FetchRemoteData.choosenReviewData;
			
			this.layout = new AnchorLayout();
			
			var headerGroupLayout:LayoutGroup = new LayoutGroup();
			headerGroupLayout.layout = new VerticalLayout();
			addChild(headerGroupLayout);

			header = new HeaderComponent();
			header.addEventListener(Event.COMPLETE, onMenuBtnTrigger);
			headerGroupLayout.addChild(header);
			
			breadcrumbComp = new BreadcrumbComponenet("Info", "Team","Ratings & Review");
			headerGroupLayout.addChild(breadcrumbComp);
			
			bulletHeadingComp = new BulletHeadingComp(CommonUtils.reviewHeading);
			headerGroupLayout.addChild(bulletHeadingComp);
			
			contentLayoutGroup = new ScrollContainer();
			contentLayoutGroup.layout = new VerticalLayout();
			addChild(contentLayoutGroup);
			
			var contentLayoutData:AnchorLayoutData = new AnchorLayoutData();
			contentLayoutData.topAnchorDisplayObject = headerGroupLayout;
			contentLayoutData.top = 20*CommonUtils.scaleValue;
			contentLayoutData.left = 20*CommonUtils.scaleValue;
			contentLayoutGroup.layoutData = contentLayoutData;
			
			reviewText = new Label();
			reviewText.text = reviewData.review;
			reviewText.textRendererProperties.wordWrap = true;
			contentLayoutGroup.addChild(reviewText);
			
			var gapingQuad1:Quad = new Quad(10,30*CommonUtils.scaleValue,0xFFFFFF);
			contentLayoutGroup.addChild(gapingQuad1);
			
			ratingImg = new ImageLoader();
			ratingImg.source = TextureAtlasManager.getAtlas().getTexture("star"+ reviewData.rating);
			ratingImg.scaleX = ratingImg.scaleY = 1.5;
			contentLayoutGroup.addChild(ratingImg);
			
			var gapingQuad:Quad = new Quad(10,10*CommonUtils.scaleValue,0xFFFFFF);
			contentLayoutGroup.addChild(gapingQuad);
			
			nameLabel = new Label();
			nameLabel.text = reviewData.name;
			nameLabel.nameList.add("employee-name-label");
			contentLayoutGroup.addChild(nameLabel);
			
			titleLabel = new Label();
			titleLabel.text = reviewData.nameTitle;
			titleLabel.nameList.add("employee-title-label");
			contentLayoutGroup.addChild(titleLabel);
			
			super.initialize();
		}
		
		override public function dispose():void
		{
			FetchRemoteData.choosenReviewData = null;
			super.dispose();
		}
		
		
		override protected function draw():void
		{
			super.draw();
			
			reviewText.width = this.width - 40*CommonUtils.scaleValue;
			contentLayoutGroup.height = this.height - contentLayoutGroup.y - 30*CommonUtils.scaleValue;
		}
		
		private function onMenuBtnTrigger(event:Event):void
		{
			this.dispatchEventWith(Event.COMPLETE);
		}
	}
}